import Vue from "vue";
import VueRouter from "vue-router";

// import Home from "../components/Home";
// import About from "../components/About";
// import User from "../components/User";

const Home = () => import('../components/Home')
const HomeNews = () => import('../components/HomeNews')
const HomeMessage = () => import('../components/HomeMessage')
const About = () => import('../components/About')
const User = () => import('../components/User')
const Profile = () => import('../components/Profile')

Vue.use(VueRouter)

const routers = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    component: Home,
    meta: {
      title: '首页'
    },
    children: [
      // 嵌套路由的默认重定向
      // {
      //   path: '/',
      //   redirect: 'news'
      // },
      // 嵌套路由的路径
      {
        path: 'news',
        component: HomeNews
      },
      {
        path: 'message',
        component: HomeMessage
      }
    ]
  },
  {
    path: '/about',
    component: About,
    meta: {
      title: '关于'
    }
  },
  {
    path: '/user/:routeUserId',
    component: User,
    meta: {
      title: '用户'
    }
  },
  {
    path: '/profile',
    component: Profile,
    meta: {
      title: '档案'
    }
  }
]

const vueRouter = new VueRouter({
  routes: routers,
  mode: 'history',
  linkActiveClass: 'active'
});


vueRouter.beforeEach((to, from, next) => {
  // console.log(to);
  document.title = to.matched[0].meta.title
  next()
})

export default vueRouter
